import { defineStore } from 'pinia'
import { ref } from 'vue'

const initState = { nickname: '', avatar: '' }

export const useSysStore = defineStore(
  'system',
  () => {
    // 生产环境
    // const appkey = ref('dingymssriipkhu8qvnv')
    // const appsecret = ref('e-DxhEp8roRtPgonPUd0s_hGn0nIyB2GxFj-7hoDfMGu5lrta-wO4spdpc7lm_v2')
    // const corpId = ref('dingaf5b2f29262cbe20f2c783f7214b6d69')

    // 测试环境
    const appkey = ref('dingt5iopfihq1jqgyri')
    const appsecret = ref('rajzbuJ65ALPQV0IKlGEfyVDmAsFsBF90HxdduuvF5N2_lTkPwP1rcZLWrFPL4uj')
    const corpId = ref('dingaf5b2f29262cbe20f2c783f7214b6d69')

    const token = ref('')
    const roles = ref([])

    const userInfo = ref({})

    const setToken = (newToken: string) => {
      token.value = newToken
    }
    const setRoles = (newVal) => {
      roles.value = newVal
    }
    const setUserInfo = (newVal) => {
      userInfo.value = newVal
    }
    const loginOut = () => {
      token.value = ''
      userInfo.value = {}
    }
    return {
      appkey,
      appsecret,
      corpId,
      token,
      setToken,
      setUserInfo,
      userInfo,
      loginOut,
      roles,
      setRoles,
    }
  },
  {
    persist: true,
  },
)
